package com.candy.control;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class LoginServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
//        获取初始化参数
        String username=config.getInitParameter("username");
        String password=config.getInitParameter("password");
        System.out.println("获取的初始化参数，username:"+username+",password:"+password);
//        获取所有初始化参数的名称
        Enumeration em=config.getInitParameterNames();
        while(em.hasMoreElements()){
            System.out.println("初始化参数的名字："+em.nextElement());
        }
//        获取Servlet的name属性值
        System.out.println("ServletName:"+config.getServletName());
//        获取ServletContext对象
        ServletContext context=config.getServletContext();
//        获取应用范围的初始化参数
        String contextVaule=context.getInitParameter("ContextParamName");
        System.out.println("ContextParamValue:"+contextVaule);
//        获取服务的根路径
        System.out.println("服务的根路径："+context.getContextPath());
//        获取其他路径的ServletContext对象
        System.out.println("LoginServlet2:"+context.getContext("/javaweb20250324/loginServlet"));
//   获取web容器的版本
        System.out.println("Web容器："+context.getServerInfo());
//        获取Servlet的主版本号
        System.out.println("Servlet的主版本号："+context.getMajorVersion());
        //        获取Servlet的次版本号
        System.out.println("Servlet的次版本号："+context.getMinorVersion());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到客户端的post请求");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到客户端的get请求");
        String username=req.getParameter("username");
        String userpwd=req.getParameter("userpwd");
        System.out.println("username:"+username);
        System.out.println("userpwd:"+userpwd);
    }
}
